package com.atguigu.controller;

import com.atguigu.entity.SkuInfo;
import com.atguigu.feign.CartFeignClient;
import com.atguigu.feign.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ：Hachimen
 * @date ：Created in 2021/9/4 19:11
 * @description：
 * @modified By：
 * @version:
 */
@Controller
public class WebCartController {
    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;
    //跳转到加入购物车成功页面
    @RequestMapping("addCart.html")
    public String addCart(@RequestParam Long skuId, @RequestParam Integer skuNum, HttpServletRequest request){
        cartFeignClient.addToCart(skuId,skuNum);
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);
        return "cart/addCart";
    }

    //2.购物车列表展示
    @GetMapping("cart.html")
    public String cartList(){
        return "cart/index";
    }

}
